﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace GameLib1
{
    /// <summary>
    /// TODO:
    /// * Animation System (don't forget to smooth with DT)
    /// * Matrix Transformation - make rotation draw at middle of object
    /// </summary>
    class GameObject
    {
        public enum FLOOR
        {
            WALL,
            GRASS,
            STONE,
        }
        public Vector2 mPos, mVel, mAcc ;
        public Texture2D mTexture;
        public Circle mCircle;
        public float mLife;
        public float mExperience;
        public float mRotation, mScale;
        public Matrix mTransform;

        public GameObject( Vector2 pos, String texture_name )
        {
            mPos = pos;
            mScale = 1.0f;
            mVel = new Vector2(0);
            mAcc = new Vector2(0);
            mTexture = TextureManager.current.texture( texture_name ) ;
            if (mTexture != null)
                mCircle = new Circle(mPos, (mTexture.Width / 2.0f) * mScale);
            else
                mCircle = new Circle(); 

            mTransform = Matrix.Identity;
            mRotation = 0;
            mLife = 0;
            mExperience = 0;
        }

        public virtual void Update(float dt)
        {
            mPos = 0.5f * mAcc * dt * dt + mVel * dt + mPos;
            mVel = mAcc * dt + mVel;
            mAcc.X = 0;
            mAcc.Y = 0;

            mCircle.mPos = mPos;

            Matrix scale = Matrix.CreateScale(mScale)        ;
            Matrix rot   = Matrix.CreateRotationZ(mRotation) ;
            Matrix trans = new Matrix() ;
            if( mTexture != null )
                trans = Matrix.CreateTranslation(mPos.X, mPos.Y, 0);

            mTransform = scale;

            mTransform *= rot;

            mTransform *= trans;
        }

        public bool CollidesWith(GameObject rhs)
        {
            return mCircle.DeltaCollidesWith(mVel, rhs.mCircle, rhs.mVel);
        }


    }
}
